package com.ns.school.common.utils;

import com.ns.school.common.constant.StaticVar;
import com.ns.school.common.exception.MyException;
import org.apache.commons.lang3.time.DateUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 日期工具类
 *
 * @author Spark
 */
public class DateUtil extends DateUtils {

    public static final String sdf01 = "yyyy";
    public static final String sdf02 = "MM";
    public static final String sdf03 = "dd";
    public static final String sdf04 = "HH";
    public static final String sdf05 = "yyyyMM";
    public static final String sdf06 = "yyyyMMdd";
    public static final String sdf07 = "yyyy-MM-dd HH:mm:ss";
    public static final String sdf08 = "MM/dd HH:mm";
    public static final String sdf09 = "yyyy-MM-dd";
    public static final String sdf10 = "yyyy-MM";
    public static final String sdf11 = "yyyyMMddHHmmss";
    public static final String sdf12 = "yyyyMMddHHmmssSSS";
    public static final String sdf13 = "yyyy年MM月";
    public static final String sdf14 = "yyyy/MM/dd";
    public static final String sdf15 = "yyyy年MM月dd日";
    public static final String sdf16 = "HH:mm:ss";
    public static final String sdf17 = "MM/dd/yyyy HH:mm:ss";
    public static final String sdf18 = "HH:mm:ss";
    public static final String sdf19 = "yyyy-MM-dd HH:mm";
    public static final String sdf20 = "MM-dd";
    public static final String sdf21 = "HH:mm";
    public static final String sdf22 = "yyyy.MM.dd";
    public static final String sdf23 = "MM月dd日";
    public static final String sdf24 = "MM-dd HH:mm";
    public static final String sdf25 = "yyyy/MM/dd HH:mm:ss";
    public static final String sdf26 = "yyyy.MM.dd HH:mm:ss";
    public static final String sdf27 = "MM月dd日 HH:mm";
    public static final String sdf28 = "HHmm";
    public static final String sdf29 = "yyyyMMddHHmm";
    public static final String sdf30 = "mm";
    public static final String sdf31 = "M月d日";
    public static final String sdf32 = "M.d";
    public static final String sdf33 = "yyyyMMddHH";
    public static final String sdf34 = "yy-MM-dd";
    public static final String sdf35 = "yy";

    public static final String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
    public static final double ONE_DAY_MS = 1000 * 60 * 60 * 24.0;
    public static final double ONE_HOUR_MS = 1000 * 60 * 60.0;


    public static String getDateFormat(final Date date, final String format) {
        return getDateFormat(format).format(date);
    }

    public static Date getDateFormat(final String date, final String pattern) {
        try {
            if (StrUtil.isEmpty(date)) {
                return null;
            }
            return getDateFormat(pattern).parse(date);
        } catch (ParseException e) {
            throw new MyException(e);
        }
    }

    private static final ThreadLocal<ConcurrentHashMap<String, SimpleDateFormat>> TL_SDF = ThreadLocal.withInitial(ConcurrentHashMap::new);

    public static void sdfClear() {
        TL_SDF.remove();
    }

    public static SimpleDateFormat getDateFormat(final String pattern) {
        ConcurrentHashMap<String, SimpleDateFormat> map = TL_SDF.get();
        SimpleDateFormat sdf = map.get(pattern);
        if (sdf == null) {
            sdf = new SimpleDateFormat(pattern);
            map.putIfAbsent(pattern, sdf);
        }
        return sdf;
    }

    /**
     * 日期路径 即年-月 如2022-02
     */
    public static String datePath() {
        return getDateNow(sdf10);
    }

    public static String getDateNow(final String format) {
        return getDateFormat(getNowDate(), format);
    }

    /**
     * 获取当前系统的时间-不含毫秒
     */
    public static Date getNowDate() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    /**
     * 获取当前系统的11位时间-int
     */
    public static int getTimeNowInt() {
        return getTimeNow().intValue();
    }

    /**
     * 获取当前系统的11位时间-int
     */
    public static Long getTimeNow() {
        return getNowDate().getTime() / 1000;
    }

    /**
     * 获取当前系统的年份
     */
    public static String getNowYearShort() {
        return getDateFormat(new Date(), sdf35);
    }

    /**
     * 获取当前系统的14位时间-long
     *
     * @return
     */
    public static long getNowTime() {
        return Long.parseLong(getNowTimeStr());
    }

    /**
     * 获取当前系统的14位时间-yyyyMMddHHmmss
     *
     * @return
     */
    public static String getNowTimeStr() {
        return format11(new Date());
    }

    public static String format01(Date date) {
        return getDateFormat(date, sdf01);
    }

    public static Date format01(String date) {
        return getDateFormat(date, sdf01);
    }

    public static String format02(Date date) {
        return getDateFormat(date, sdf02);
    }

    public static Date format02(String date) {
        return getDateFormat(date, sdf02);
    }

    public static String format03(Date date) {
        return getDateFormat(date, sdf03);
    }

    public static Date format03(String date) {
        return getDateFormat(date, sdf03);
    }

    public static String format04(Date date) {
        return getDateFormat(date, sdf04);
    }

    public static Date format04(String date) {
        return getDateFormat(date, sdf04);
    }

    public static String format05(Date date) {
        return getDateFormat(date, sdf05);
    }

    public static Date format05(String date) {
        return getDateFormat(date, sdf05);
    }

    public static int format06Int(Date date) {
        return Integer.parseInt(format06(date));
    }

    public static String format06(Date date) {
        return getDateFormat(date, sdf06);
    }

    public static Date format06(String date) {
        return getDateFormat(date, sdf06);
    }

    public static Date format06(Long date) {
        return getDateFormat(date.toString(), sdf06);
    }

    public static Date format06(Integer date) {
        return getDateFormat(date.toString(), sdf06);
    }

    public static String format07(Date date) {
        return getDateFormat(date, sdf07);
    }

    public static Date format07(String date) {
        return getDateFormat(date, sdf07);
    }

    public static String format08(Date date) {
        return getDateFormat(date, sdf08);
    }

    public static Date format08(String date) {
        return getDateFormat(date, sdf08);
    }

    public static String format09(Date date) {
        return getDateFormat(date, sdf09);
    }

    public static Date format09(String date) {
        return getDateFormat(date, sdf09);
    }

    public static String format10(Date date) {
        return getDateFormat(date, sdf10);
    }

    public static Date format10(String date) {
        return getDateFormat(date, sdf10);
    }

    public static String format11(Date date) {
        return getDateFormat(date, sdf11);
    }

    public static Long format11Long(Date date) {
        return Long.parseLong(getDateFormat(date, sdf11));
    }

    public static Date format11(String date) {
        return getDateFormat(date, sdf11);
    }

    public static Date format11(Long date) {
        return getDateFormat(date.toString(), sdf11);
    }

    public static String format12(Date date) {
        return getDateFormat(date, sdf12);
    }

    public static Date format12(String date) {
        return getDateFormat(date, sdf12);
    }

    public static String format13(Date date) {
        return getDateFormat(date, sdf13);
    }

    public static Date format13(String date) {
        return getDateFormat(date, sdf13);
    }

    public static String format14(Date date) {
        return getDateFormat(date, sdf14);
    }

    public static Date format14(String date) {
        return getDateFormat(date, sdf14);
    }

    public static String format15(Date date) {
        return getDateFormat(date, sdf15);
    }

    public static Date format15(String date) {
        return getDateFormat(date, sdf15);
    }

    public static String format16(Date date) {
        return getDateFormat(date, sdf16);
    }

    public static Date format16(String date) {
        return getDateFormat(date, sdf16);
    }

    public static String format17(Date date) {
        return getDateFormat(date, sdf17);
    }

    public static Date format17(String date) {
        return getDateFormat(date, sdf17);
    }

    public static String format18(Date date) {
        return getDateFormat(date, sdf18);
    }

    public static Date format18(String date) {
        return getDateFormat(date, sdf18);
    }

    public static String format19(Date date) {
        return getDateFormat(date, sdf19);
    }

    public static Date format19(String date) {
        return getDateFormat(date, sdf19);
    }

    public static String format20(Date date) {
        return getDateFormat(date, sdf20);
    }

    public static Date format20(String date) {
        return getDateFormat(date, sdf20);
    }

    public static String format21(Date date) {
        return getDateFormat(date, sdf21);
    }

    public static Date format21(String date) {
        return getDateFormat(date, sdf21);
    }

    public static String format21toStr(Long date) {
        return getDateFormat(sdf21).format(format11(String.valueOf(date)));
    }

    public static String format22(Date date) {
        return getDateFormat(date, sdf22);
    }

    public static Date format22(String date) {
        return getDateFormat(date, sdf22);
    }

    public static String format23(Date date) {
        return getDateFormat(date, sdf23);
    }

    public static Date format23(String date) {
        return getDateFormat(date, sdf23);
    }

    public static String format24(Date date) {
        return getDateFormat(date, sdf24);
    }

    public static Date format24(String date) {
        return getDateFormat(date, sdf24);
    }

    public static String format25(Date date) {
        return getDateFormat(date, sdf25);
    }

    public static Date format25(String date) {
        return getDateFormat(date, sdf25);
    }

    public static String format26(Date date) {
        return getDateFormat(date, sdf26);
    }

    public static Date format26(String date) {
        return getDateFormat(date, sdf26);
    }

    public static String format27(Date date) {
        return getDateFormat(date, sdf27);
    }

    public static Date format27(String date) {
        return getDateFormat(date, sdf27);
    }

    public static String format28(Date date) {
        return getDateFormat(date, sdf28);
    }

    public static Date format28(String date) {
        return getDateFormat(date, sdf28);
    }

    public static String format29(Date date) {
        return getDateFormat(date, sdf29);
    }

    public static Date format29(String date) {
        return getDateFormat(date, sdf29);
    }

    public static Long getTimeStamp29() {
        return Long.parseLong(format29(getNowDate()));
    }

    public static String format30(Date date) {
        return getDateFormat(date, sdf30);
    }

    public static Date format30(String date) {
        return getDateFormat(date, sdf30);
    }

    public static String format31(Date date) {
        return getDateFormat(date, sdf31);
    }

    public static Date format31(String date) {
        return getDateFormat(date, sdf31);
    }

    public static String Long11ToStr04(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf04).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr05(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf05).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr06(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf06).format(getDateFormat(time.toString(), sdf11));
    }

    public static Long Long11ToLong06(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return Long.parseLong(Long11ToStr06(time));
    }

    public static Integer Long11ToInt06(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return Integer.parseInt(Long11ToStr06(time));
    }

    public static String Long11ToStr07(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf07).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr09(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf09).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr14(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf14).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr15(Long time) {
        if (time == null) {
            return null;
        }
        return getDateFormat(sdf15).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr18(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf18).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr19(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf19).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr20(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf20).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr21(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf21).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr22(Long time) {
        if (time == null) {
            return null;
        }
        return getDateFormat(sdf22).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr23(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf23).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr24(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf24).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr27(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf27).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr28(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf28).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr29(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf29).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr30(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf30).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr31(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf31).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Long11ToStr34(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return getDateFormat(sdf34).format(getDateFormat(time.toString(), sdf11));
    }

    public static String Str11ToStr06(String time) {
        if (time == null) {
            return null;
        }
        return getDateFormat(sdf06).format(getDateFormat(time, sdf11));
    }

    public static String Str11ToStr16(String time) {
        return getDateFormat(sdf16).format(format11(time));
    }

    public static String Str06ToLong09(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf09).format(getDateFormat(time, sdf06));
    }

    public static String Str05ToLong10(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf10).format(getDateFormat(time, sdf05));
    }

    public static String Str06ToStr32(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf32).format(getDateFormat(time, sdf06));
    }

    public static String Str06ToStr23(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf23).format(getDateFormat(time, sdf06));
    }

    public static String Long06ToStr09(Long time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf09).format(getDateFormat(time.toString(), sdf06));
    }

    public static String Int06ToStr09(Integer time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf09).format(getDateFormat(time.toString(), sdf06));
    }

    public static String Long06ToString14(Long time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf14).format(getDateFormat(time.toString(), sdf06));
    }

    public static Long Str06ToLong11(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return Long.parseLong(getDateFormat(sdf11).format(getDateFormat(time, sdf06)));
    }

    public static Long Str07ToLong11(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return Long.parseLong(getDateFormat(sdf11).format(getDateFormat(time, sdf07)));
    }

    public static String Str06ToStr09(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf09).format(getDateFormat(time, sdf06));
    }

    public static String Str06ToStr05(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf05).format(getDateFormat(time, sdf06));
    }

    public static String Str05ToStr10(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf10).format(getDateFormat(time, sdf05));
    }

    public static Long Str19ToLong11(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return Long.parseLong(getDateFormat(sdf11).format(getDateFormat(time, sdf19)));
    }

    public static String Str19ToStr24(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf24).format(getDateFormat(time, sdf19));
    }

    public static String Str19ToStr34(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getDateFormat(sdf34).format(getDateFormat(time, sdf19));
    }

    public static Long Str09ToLong11(String time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return Long.parseLong(getDateFormat(sdf11).format(getDateFormat(time, sdf09)));
    }

    public static int getFormat11Time(Long time) {
        if (time == null || time <= 0) {
            return 0;
        }
        return (int) ((format11(time.toString()).getTime()) / 1000);
    }

    /**
     * 获取当前时间(yyyy-MM-dd HH:mm:ss)
     *
     * @return
     */
    public static String getNowTime07Str() {
        return getDateFormat(sdf07).format(new Date());
    }

    /**
     * 获取当前时间(yyyy-MM-dd HH:mm:ss)
     *
     * @return
     */
    public static String getNowTime17Str() {
        return getDateFormat(sdf17).format(new Date());
    }

    /**
     * 获取当前时间(yyyy-MM-dd HH:mm)
     *
     * @return
     */
    public static String getNowTime19Str() {
        return getDateFormat(sdf19).format(new Date());
    }

    /**
     * 获取当前时间(yyyy-MM-dd)
     *
     * @return
     */
    public static String getNowTime09Str() {
        return getDateFormat(sdf09).format(new Date());
    }

    /**
     * 获取当前时间(yyyyMMdd)
     *
     * @return
     */
    public static String getNowTime06Str() {
        return getDateFormat(sdf06).format(new Date());
    }

    /**
     * 获取当前时间(yyyyMMdd)
     *
     * @return
     */
    public static String getNowTime33Str() {
        return getDateFormat(sdf33).format(new Date());
    }

    /**
     * 获取当前时间(yyyyMM)
     *
     * @return
     */
    public static String getNowTime05Str() {
        return getDateFormat(sdf05).format(new Date());
    }

    /**
     * 获取当前日期周几
     *
     * @return
     */
    public static String getWeek(String datetime, String format) {
        SimpleDateFormat sdf = getDateFormat(format);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDays[w];
    }

    /**
     * 获取当前日期周几 1- 7
     *
     * @return
     */
    public static Integer getWeekNumOneToSeven(String datetime) {
        SimpleDateFormat sdf = getDateFormat(sdf11);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int weekNum = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekNum == 0 ? 7 : weekNum;
    }

    /**
     * 拼接当前时分日期
     *
     * @param startTime yyyy-MM-dd HH:mm
     * @param endTime   yyyy-MM-dd HH:mm
     * @return yyyy-MM-dd HH:mm-HH:mm
     */
    public static String getDateYmdBetween(String startTime, String endTime) {
        return startTime + "-" + endTime.substring(11);
    }

    /**
     * 拼接当前日期
     *
     * @return yyyy-MM-dd(week) HH:mm:ss
     */
    public static String getYmdWeekHms() {
        String format07 = format07(new Date());
        SimpleDateFormat sdf = getDateFormat(sdf07);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(format07);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return format07.substring(0, 10) + "(" + weekDays[w] + ")" + format07.substring(10);
    }

    /**
     * 拼接当前日期
     *
     * @param datetime yyyyMMddHHmmss
     * @return yyyy-MM-dd(week) HH:mm:ss
     */
    public static String getYmdWeekHms(String datetime) {
        SimpleDateFormat sdf = getDateFormat(sdf07);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            sdf = getDateFormat(sdf19);
            try {
                date = sdf.parse(datetime);
                cal.setTime(date);
            } catch (ParseException e2) {
                e2.printStackTrace();
            }
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return datetime.substring(0, 10) + "(" + weekDays[w] + ")" + datetime.substring(10);
    }

    /**
     * 拼接当前日期
     *
     * @param datetime yyyyMMddHHmmss
     * @return MM-dd(week) HH:mm:ss
     */
    public static String getYmdWeekHms2(String datetime) {
        SimpleDateFormat sdf = getDateFormat(sdf07);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            sdf = getDateFormat(sdf19);
            try {
                date = sdf.parse(datetime);
                cal.setTime(date);
            } catch (ParseException e2) {
                e2.printStackTrace();
            }
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return datetime.substring(5, 10) + "(" + weekDays[w] + ")" + datetime.substring(10);
    }

    /**
     * 获取当前日期周几
     *
     * @return
     */
    public static String getWeek(String datetime) {
        SimpleDateFormat sdf = getDateFormat(sdf11);
        Calendar cal = Calendar.getInstance();
        Date date;
        try {
            date = sdf.parse(datetime);
            cal.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return weekDays[w];
    }

    /**
     * 获取当前日期周几
     *
     * @return
     */
    public static Integer getWeekNum(String datetime) {
        if (StrUtil.isEmpty(datetime)) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(format11(datetime));
        int week = cal.get(Calendar.DAY_OF_WEEK);
        return week == 1 ? 7 : (week - 1);
    }

    /**
     * 获取当前日期周几(带前后小括号)
     *
     * @return
     */
    public static String getWeekParentheses(String datetime, String format) {
        return "(" + getWeek(datetime, format) + ")";
    }

    /**
     * 获取当前日期周几(带前后小括号)
     *
     * @return
     */
    public static String getWeekParentheses(String datetime) {
        return "(" + getWeek(datetime) + ")";
    }

    /**
     * 获取当前日期周几(带前后小括号)
     *
     * @return
     */
    public static String getWeekParentheses(Long datetime) {
        if (datetime == null || datetime < 0) {
            return null;
        }
        return "(" + getWeek(datetime.toString()) + ")";
    }

    /**
     * 获取当前日期当周的每一天
     *
     * @return
     */
    public static Map<Integer, String> getWeekDayList() {
        return getWeekDayList(getNowTime09Str());
    }

    /**
     * 获取指定日期当周的每一天
     *
     * @param date yyyy-MM-dd
     * @return
     */
    public static Map<Integer, String> getWeekDayList(String date) {
        if (StrUtil.isEmpty(date)) {
            return null;
        }
        return getWeekDayList(format09(date));
    }

    /**
     * 获取指定日期当周的每一天
     *
     * @param time yyyyMMddHHmmss
     * @return
     */
    public static Map<Integer, String> getWeekDayList(Long time) {
        if (StrUtil.isEmpty(time)) {
            return null;
        }
        return getWeekDayList(format11(time));
    }

    /**
     * 获取指定日期当周的每一天
     *
     * @param date yyyy-MM-dd
     * @return
     * @throws Exception
     */
    public static Map<Integer, String> getWeekDayList(Date date) {
        if (date == null) {
            return null;
        }
        Map<Integer, String> map = new LinkedHashMap<>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            cal.add(Calendar.DATE, -1);// 如果是周日就将当前日期减一天
        }

        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期
        map.put(1, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); // 获取本周二的日期
        map.put(2, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); // 获取本周三的日期
        map.put(3, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY); // 获取本周四的日期
        map.put(4, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); // 获取本周五的日期
        map.put(5, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); // 获取本周六的日期
        map.put(6, getDateFormat(sdf09).format(cal.getTime()));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // 这种输出的是上个星期周日的日期，因为老外那边把周日当成第一天
        cal.add(Calendar.WEEK_OF_YEAR, 1); // 增加一个星期，才是我们中国人理解的本周日的日期
        map.put(7, getDateFormat(sdf09).format(cal.getTime()));

        return map;
    }

    /**
     * 根据日期获取星期
     *
     * @param pTime
     * @return
     */
    public static String dayForWeek(Long pTime) {
        if (pTime == null) {
            return null;
        }
        return dayForWeek(pTime.toString());
    }

    /**
     * 将日期转为周几
     *
     * @param pTime
     * @return
     */
    public static String dayForWeek(String pTime) {
        if (StrUtil.isEmpty(pTime)) {
            return null;
        }
        Calendar c = Calendar.getInstance();
        c.setTime(format11(pTime));
        int dayForWeek = 0;
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            dayForWeek = 7;
        } else {
            dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
        }
        switch (dayForWeek) {
            case 1:
                return "周一";
            case 2:
                return "周二";
            case 3:
                return "周三";
            case 4:
                return "周四";
            case 5:
                return "周五";
            case 6:
                return "周六";
            case 7:
                return "周日";
        }
        return null;
    }

    /**
     * 获取指定日期后的七天
     *
     * @param date yyyy-MM-dd
     * @return
     * @throws Exception
     */
    public static Map<Integer, String> getNextSevenDayList(String date) {
        if (StrUtil.isEmpty(date)) {
            return null;
        }
        Map<Integer, String> map = new LinkedHashMap<>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));

        int weekIndex = 0;
        for (int i = 0; i < 7; i++) {
            weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;// 老外的周日是每周的第一天
            if (weekIndex == 0) {
                weekIndex = 7;
            }
            map.put(weekIndex, getDateFormat(sdf09).format(cal.getTime()));
            cal.add(Calendar.DATE, 1);// 获取下一天
        }

        return map;
    }

    /**
     * 获取过去n天yyyyMMdd
     *
     * @param n(大于0表示过去n天)
     * @return
     */
    public static int getPreDay06(int n) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -n);
        return Integer.parseInt(getDateFormat(sdf06).format(cal.getTime()));
    }

    /**
     * 获取昨天yyyyMMdd
     *
     * @return
     */
    public static int getPreDay06() {
        return getPreDay06(1);
    }

    /**
     * 获取今天yyyyMMdd
     *
     * @return
     */
    public static int getNowDay06() {
        return getPreDay06(0);
    }

    /**
     * 获取过去n天yyyy-MM-dd
     *
     * @param n (大于0表示过去n天)
     * @return
     */
    public static String getPreDay(int n) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -n);
        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取过去n天MM-dd
     *
     * @param n (大于0表示过去n天)
     * @return
     */
    public static String getPreDay20(int n) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -n);
        return getDateFormat(sdf20).format(cal.getTime());
    }

    /**
     * 获取昨天yyyy-MM-dd
     *
     * @return
     */
    public static String getPreDay() {
        return getPreDay(1);
    }

    /**
     * 获取昨天MM-dd
     *
     * @return
     */
    public static String getPreDay20() {
        return getPreDay20(1);
    }

    /**
     * 获取明天yyyy-MM-dd
     *
     * @return
     */
    public static String getNextDay() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 1);
        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取上一天yyyy-MM-dd
     *
     * @param date
     * @return
     */
    public static String getPreDay(String date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));
        cal.add(Calendar.DATE, -1);
        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取上N天yyyyMMdd
     *
     * @param date yyyyMMdd
     * @param day  减去的天数
     * @return
     */
    public static int getPreDay06(Integer date, int day) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format06(date.toString()));
        cal.add(Calendar.DATE, -day);
        return Integer.parseInt(getDateFormat(sdf06).format(cal.getTime()));
    }

    /**
     * 获取yyyyMMddHHmmss相差天数日期
     *
     * @param date
     * @return yyyyMMddHHmmss
     */
    public static String getSdf6PreDay(String date, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format11(date));
        cal.add(Calendar.DATE, amount);
        return getDateFormat(sdf06).format(cal.getTime());
    }

    /**
     * 获取下一天
     *
     * @param date
     * @return
     */
    public static String getNextDay(String date, String format) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getDateFormat(date, format));
        cal.add(Calendar.DATE, 1);
        return getDateFormat(format).format(cal.getTime());
    }

    /**
     * 获取下一天yyyy-MM-dd
     *
     * @param date
     * @return
     */
    public static String getNextDay(String date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));
        cal.add(Calendar.DATE, 1);
        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取上一周的周一
     *
     * @param date
     * @return
     */
    public static String getPreWeekMonDay(String date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期
        cal.add(Calendar.WEEK_OF_YEAR, -1); // 减少一个星期

        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取给定时间的周一
     *
     * @param date
     * @return
     */
    public static String getThisWeekMonDay(Long date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(Long11ToStr09(date)));
        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            cal.add(Calendar.DATE, -1);// 如果是周日就将当前日期减一天
        }
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期

        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取下一周的周一
     *
     * @param date
     * @return
     */
    public static String getNextWeekMonDay(String date) {
        if (StrUtil.isEmpty(date)) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));

        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期
        cal.add(Calendar.WEEK_OF_YEAR, 1); // 增加一个星期

        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取当前日期的增加一周的日子
     *
     * @param date
     * @return
     */
    public static String getNextWeekDay(String date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format11(date));
        cal.add(Calendar.WEEK_OF_YEAR, 1); // 增加一个星期
        return getDateFormat(sdf11).format(cal.getTime());
    }


    /**
     * 获取当前日期的增加一周的日子
     *
     * @param date
     * @return
     */
    public static String getNextWeekDay09(String date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(format09(date));
        cal.add(Calendar.WEEK_OF_YEAR, 1); // 增加一个星期

        return getDateFormat(sdf09).format(cal.getTime());
    }

    /**
     * 获取当前日期的增加一周的日子
     *
     * @param date
     * @return
     */
    public static Long getNextWeekDay(Long date) {
        if (date == null) {
            return null;
        }
        return Long.parseLong(getNextWeekDay(String.valueOf(date)));
    }

    /**
     * 时间字符串转去符号
     *
     * @param time
     * @return
     */
    public static String dateReplace2Int(String time) {
        return time.replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "");
    }

    /**
     * 时间字符串转Long
     *
     * @param time
     * @return
     */
    public static Long StringToLong(String time) {
        return Long.parseLong(dateReplace2Int(time));
    }

    /**
     * Long -> yyyy-MM-dd HH:mm:ss
     *
     * @param time
     * @return
     */
    public static String LongToString(Long time) {
        if (time == null) {
            return null;
        }
        return getDateFormat(sdf07).format(format11(Long.toString(time)));
    }

    /**
     * long转年月日
     *
     * @param time
     * @return
     */
    public static String LongToYear(Long time) {
        String dateS = getDateFormat(sdf07).format(format11(Long.toString(time)));
        return dateS.substring(0, dateS.length() - 9);
    }

    /**
     * long转年月日分秒
     *
     * @param time
     * @return
     */
    public static String LongToYearMinutes(Long time) {
        String dateS = getDateFormat(sdf07).format(format11(Long.toString(time)));
        return dateS.substring(0, dateS.length() - 3);
    }

    /**
     * long转日分秒
     *
     * @param time
     * @return
     */
    public static String LongToTime(Long time) {
        SimpleDateFormat sdf = getDateFormat(sdf16);
        return sdf.format(time);
    }

    /**
     * 时间转年月日时分秒(yyyyMMddHHmmss)
     *
     * @param time
     * @return
     */
    public static Long DateToLong(Date time) {
        SimpleDateFormat sdf = getDateFormat(sdf11);
        return Long.parseLong(sdf.format(time));
    }

    /**
     * 获取两个时间相差秒数,不足一秒不计算
     *
     * @param time1
     * @param time2
     * @return
     */
    public static int betweenSecond(Long time1, Long time2) {
        Date dt1 = DateUtil.format11(String.valueOf(time1));
        Date dt2 = DateUtil.format11(String.valueOf(time2));
        long s = (dt1.getTime() - dt2.getTime()) / 1000;
        return (int) Math.abs(s);
    }

    /**
     * 计算两个日期之间相差的天数,不足一天按一天计算,小于0按0计算
     *
     * @param small 较小的时间 sdf11
     * @param big   较大的时间 sdf11
     * @return
     */
    public static int betweenDayC(String small, String big) {
        Date sdate = format11(small);// 较小的时间
        Date bdate = format11(big);// 较大的时间
        Calendar cal = Calendar.getInstance();
        cal.setTime(sdate);
        long time1 = cal.getTimeInMillis();
        cal.setTime(bdate);
        long time2 = cal.getTimeInMillis();
        int days = (int) (Math.ceil((time2 - time1) / (1000 * 3600 * 24.0)));
        return Math.max(days, 0);
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天按1天计算)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayC(Date smallDate, Date bigDate) {
        double time = (bigDate.getTime() - smallDate.getTime()) / ONE_DAY_MS;
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天不计算)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayF(Date smallDate, Date bigDate) {
        double time = (bigDate.getTime() - smallDate.getTime()) / ONE_DAY_MS;
        return (int) Math.floor(time);// 向下取整
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天不计算)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayF(String smallDate, String bigDate) {
        if (StrUtil.isEmpty(smallDate) || StrUtil.isEmpty(bigDate)) {
            throw new RuntimeException("参数错误");
        }
        return betweenDayF(format11(smallDate), format11(bigDate));
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天不计算)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayFC06(String smallDate, String bigDate) {
        if (StrUtil.isEmpty(smallDate) || StrUtil.isEmpty(bigDate)) {
            throw new RuntimeException("参数错误");
        }
        return betweenDayF(format06(smallDate), format06(bigDate));
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天按1天计算)
     * yyyyMMdd
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayC06(String smallDate, String bigDate) {
        if (StrUtil.isEmpty(smallDate) || StrUtil.isEmpty(bigDate)) {
            throw new RuntimeException("参数错误");
        }
        double time = (format06(bigDate).getTime() - format06(smallDate).getTime()) / ONE_DAY_MS;
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天按1天计算)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return 相差天数
     */
    public static int betweenDayC(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            throw new RuntimeException("参数错误");
        }
        double time = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / ONE_DAY_MS;
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 计算两个日期之间相差的时间(x天y时z分)
     *
     * @param smallDate 较小的时间
     * @param bigDate   较大的时间
     * @return x天y时z分
     */
    public static String betweenDayD3(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            throw new RuntimeException("参数错误");
        }
        StringBuilder res = new StringBuilder();
        long second = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / 1000;
        if (second <= 0) {
            res.append("0");
        }
        if (second < 60) {
            res.append("不足1分");
        }
        if (second > (60 * 60 * 24)) {
            res.append(second / (60 * 60 * 24)).append("天");
            second = second % (60 * 60 * 24);
        }
        if (second > (60 * 60)) {
            res.append(second / (60 * 60)).append("时");
            second = second % (60 * 60);
        }
        if (second > (60)) {
            res.append(second / (60)).append("分");
        }
        return res.toString();
    }

    /**
     * 计算两个日期之间相差的天数-(不足1天不计算)
     *
     * @param smallDate 较小的时间(14)
     * @param bigDate   较大的时间(14)
     * @return 相差天数
     */
    public static Integer betweenDayF(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        double time = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / ONE_DAY_MS;
        return (int) Math.floor(time);// 向下取整
    }

    /**
     * 计算两个日期之间相差的小时数-(不足1小时按1小时计算)
     *
     * @param smallDate 较小的时间(14)
     * @param bigDate   较大的时间(14)
     * @return 相差小时数
     */
    public static Integer betweenHourC(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        double time = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / ONE_HOUR_MS;
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 计算两个日期之间相差的小时数-(不足1小时按1小时计算)
     *
     * @param smallDate 较小的时间(14)
     * @param bigDate   较大的时间(14)
     * @return 相差小时数
     */
    public static Integer betweenHourC(Date smallDate, Date bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        double time = (bigDate.getTime() - smallDate.getTime()) / ONE_HOUR_MS;
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 计算两个日期之间相差的小时数-(四舍五入,精确到2位小数)
     *
     * @param smallDate 较小的时间(14)
     * @param bigDate   较大的时间(14)
     * @return 相差小时数
     */
    public static Double betweenHourR(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        double time = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / ONE_HOUR_MS;
        return new BigDecimal(Double.toString(time)).setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

    /**
     * 计算两个日期之间相差的分钟数-(不足1分钟按1分钟计算)
     *
     * @param smallDate 较小的时间(14)
     * @param bigDate   较大的时间(14)
     * @return 相差分钟数
     */
    public static Integer betweenMinuteC(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        double time = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / (1000 * 60.0);
        return (int) Math.ceil(time);// 向上取整
    }

    /**
     * 获取两个月份相差的月数
     * yyyyMM
     *
     * @param d1 较小的日期
     * @param d2 较大的日期
     * @return 如果d1>d2返回 月数差 否则返回0
     */
    public static int betweenMonth05(String d1, String d2) {
        try {
            Calendar c1 = Calendar.getInstance();
            Calendar c2 = Calendar.getInstance();

            // 将String日期转换成date
            SimpleDateFormat sdf = getDateFormat(sdf05);
            Date date1 = sdf.parse(d1);
            Date date2 = sdf.parse(d2);
            c1.setTime(date1);
            c2.setTime(date2);

            // 判断两个日期的大小
            if (c1.getTimeInMillis() > c2.getTimeInMillis()) {
                return 0;
            }
            int year1 = c1.get(Calendar.YEAR);
            int year2 = c2.get(Calendar.YEAR);

            int month1 = c1.get(Calendar.MONTH);
            int month2 = c2.get(Calendar.MONTH);

            // 获取年的差值
            int yearInterval = year2 - year1;
            // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
            if (month2 < month1) {
                yearInterval--;
            }
            // 获取月数差值
            int monthInterval = (month2 + 12) - month1;

            monthInterval %= 12;
            return yearInterval * 12 + monthInterval + 1;
        } catch (ParseException e) {
            throw new MyException("日期格式化错误" + e.getMessage());
        }
    }

    /**
     * 获取两个日期相差的月数
     * yyyyMMdd
     *
     * @param d1 较小的日期
     * @param d2 较大的日期
     * @return 如果d1>d2返回 月数差 否则返回0
     */
    public static int betweenMonth06(String d1, String d2) throws ParseException {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();

        // 将String日期转换成date
        SimpleDateFormat sdf = getDateFormat(sdf06);
        Date date1 = sdf.parse(d1);
        Date date2 = sdf.parse(d2);
        c1.setTime(date1);
        c2.setTime(date2);

        // 判断两个日期的大小
        if (c1.getTimeInMillis() > c2.getTimeInMillis()) {
            return 0;
        }
        int year1 = c1.get(Calendar.YEAR);
        int year2 = c2.get(Calendar.YEAR);

        int month1 = c1.get(Calendar.MONTH);
        int month2 = c2.get(Calendar.MONTH);

        int day1 = c1.get(Calendar.DAY_OF_MONTH);
        int day2 = c2.get(Calendar.DAY_OF_MONTH);

        // 获取年的差值
        int yearInterval = year2 - year1;
        // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
        if (month2 < month1 || (month1 == month2 && day2 < day1)) {
            yearInterval--;
        }
        // 获取月数差值
        int monthInterval = (month2 + 12) - month1;
        if (day2 > day1) {
            monthInterval++;
        }
        monthInterval %= 12;
        return yearInterval * 12 + monthInterval;
    }

    /**
     * 计算两个日期之间相差的秒数
     *
     * @return 时:分:秒
     */
    public static String betweenSecondStr(Long smallDate, Long bigDate) {
        if (smallDate == null || bigDate == null) {
            return null;
        }
        long second = (format11(bigDate.toString()).getTime() - format11(smallDate.toString()).getTime()) / 1000;
        second = second % 86400;// 剩余秒数
        long hours = second / 3600;// 转换小时数
        second = second % 3600;// 剩余秒数
        long minutes = second / 60;// 转换分钟
        second = second % 60;// 剩余秒数
        return hours + ":" + minutes + ":" + second;
    }

    /**
     * 根据生日(yyyyMMdd)计算出生月数
     *
     * @param date 出生的时间
     * @return 相差月数
     */
    public static int getMonthsByBirthday(String date) {
        if (StrUtil.isEmpty(date)) {
            throw new RuntimeException("参数错误");
        }
        Calendar c = Calendar.getInstance();
        // c.setTime(new Date());
        int yearNow = c.get(Calendar.YEAR);
        int monthNow = c.get(Calendar.MONTH);
        int dayNow = c.get(Calendar.DAY_OF_MONTH);

        c.setTime(format06(date));
        int yearBefore = c.get(Calendar.YEAR);
        int monthBefore = c.get(Calendar.MONTH);
        int dayBefore = c.get(Calendar.DAY_OF_MONTH);

        int result = 0;
        if (yearNow == yearBefore) {
            result = monthNow - monthBefore;
            if (dayNow < dayBefore) {
                result--;
            }
        } else {
            result = ((yearNow - yearBefore) * 12) + (monthNow - monthBefore);
            if (dayNow < dayBefore) {
                result--;
            }
        }
        return result;
    }

    /**
     * 获取本年第一天 00：00：00
     */
    public static Long beginOfYear() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_YEAR, 1);// 设置为1号,当前日期既为本月第一天
        String time1 = format.format(c.getTime()) + "000000";
        return Long.parseLong(time1);
    }

    /**
     * 获取本年最后一天 23：59：59
     */
    public static Long endOfYear() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_YEAR, ca.getActualMaximum(Calendar.DAY_OF_YEAR));
        String time2 = format.format(ca.getTime()) + "235959";
        return Long.parseLong(time2);
    }

    /**
     * 获取本月第一天 00：00：00
     */
    public static Long beginOfMonth() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return Long.parseLong(format.format(c.getTime()) + "000000");
    }

    /**
     * 获取本月最后一天 23：59：59
     */
    public static Long endOfMonth() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        return Long.parseLong(format.format(ca.getTime()) + "235959");
    }

    /**
     * 获取本月第一天
     */
    public static int beginOfMonthInt() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return Integer.parseInt(format.format(c.getTime()));
    }

    /**
     * 获取本月最后一天
     */
    public static int endOfMonthInt() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        return Integer.parseInt(format.format(ca.getTime()));
    }

    /**
     * 获取上月的第一天 00：00：00
     */
    public static Long beginOfMonthLast() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return Long.parseLong(format.format(c.getTime()) + "000000");
    }

    /**
     * 获取上月的最后一天 23：59：59
     */
    public static Long endOfMonthLast() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.add(Calendar.DATE, -1);// 当月减1即为上月最后一天
        return Long.parseLong(format.format(c.getTime()) + "235959");
    }

    /**
     * 获取距离现在几个月的第一天 00：00：00
     */
    public static Long beginOfMonthLast(int m) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, (-m));
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return Long.parseLong(format.format(c.getTime()) + "000000");
    }

    /**
     * 获取距离现在几个月的最后一天 23：59：59
     */
    public static Long endOfMonthLast(int m) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, (1 - m));
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.add(Calendar.DATE, -1);// 当月减1即为上月最后一天
        return Long.parseLong(format.format(c.getTime()) + "235959");
    }

    /**
     * 获取最近三月的第一天 00：00：00
     */
    public static Long beginOfMonthLast3() {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -2);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return Long.parseLong(format.format(c.getTime()) + "000000");
    }

    /**
     * 获取本周第一天 00：00：00
     */
    public static Long beginOfWeek() {
        return beginOfWeek(0);
    }

    /**
     * 获取指定周第一天 00：00：00
     *
     * @param index 指定周偏移量
     */
    public static Long beginOfWeek(int index) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.WEEK_OF_YEAR, index);
        if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            c.add(Calendar.DATE, -1);// 周日需要减去一天
        }
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); // 获取本周一的日期

        return Long.parseLong(format.format(c.getTime()) + "000000");
    }

    /**
     * 获取本周最后一天 23：59：59
     */
    public static Long endOfWeek() {
        return endOfWeek(0);
    }

    /**
     * 获取指定周最后一天 23：59：59
     *
     * @param index 指定周偏移量
     */
    public static Long endOfWeek(int index) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar c = Calendar.getInstance();
        c.add(Calendar.WEEK_OF_YEAR, index);
        if (c.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            c.add(Calendar.WEEK_OF_YEAR, 1); // 非周日需要增加一个星期
        }
        c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // 获取本周日的日期
        return Long.parseLong(format.format(c.getTime()) + "235959");
    }

    /**
     * 获取次日的开始时间 00：00：00
     */
    public static Long beginOfDayNext(Long date) {
        if (date.toString().contains("000000")) {
            return date;
        }
        return Long.parseLong(Long11ToLong06(addDaysLong(date, 1)) + "000000");
    }

    /**
     * 获取今日的前后某天的开始时间 00：00：00 Integer i<0 往前推 i>0 往后推
     */
    public static Long beginOfDay(int i) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar ca = Calendar.getInstance();
        // ca.setTime(new Date());
        ca.add(Calendar.DATE, i);
        String time1 = format.format(ca.getTime()) + "000000";
        return Long.parseLong(time1);
    }

    /**
     * 获取指定日期的前后某天的开始时间 00：00：00 Integer i<0 往前推 i>0 往后推
     */
    public static Long beginOfDay(Date date, int i) {
        SimpleDateFormat format = getDateFormat(sdf06);
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.add(Calendar.DATE, i);
        String time1 = format.format(ca.getTime()) + "000000";
        return Long.parseLong(time1);
    }

    /**
     * 获取今日的 23：59：59
     */
    public static Long endOfDay() {
        SimpleDateFormat format = getDateFormat(sdf06);
        String time2 = format.format(new Date()) + "235959";
        return Long.parseLong(time2);
    }

    /**
     * 获取某日的最后时间 23：59：59
     */
    public static Long endOfDay(Date date) {
        SimpleDateFormat format = getDateFormat(sdf06);
        String time2 = format.format(date) + "235959";
        return Long.parseLong(time2);
    }

    /**
     * 获取今日的前后某天的开始时间 23：59：59 Integer i<0 往前推 i>0 往后推
     */
    public static Long endOfDay(int i) {
        Calendar ca = Calendar.getInstance();
        // ca.setTime(new Date());
        ca.add(Calendar.DATE, i);
        String time2 = getDateFormat(sdf06).format(ca.getTime()) + "235959";
        return Long.parseLong(time2);
    }

    /**
     * 获取指定日期的前后某天的结束时间 23：59：59 Integer i<0 往前推 i>0 往后推
     */
    public static Long endOfDay(Date date, int i) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        ca.add(Calendar.DATE, i);
        String time2 = getDateFormat(sdf06).format(ca.getTime()) + "235959";
        return Long.parseLong(time2);
    }

    /**
     * 获取今日的00：00：00
     */
    public static Long beginOfDay() {
        SimpleDateFormat format = getDateFormat(sdf06);
        String time1 = format.format(new Date()) + "000000";
        return Long.parseLong(time1);
    }

    /**
     * 获取某日的开始时间 00：00：00
     */
    public static Long beginOfDay(Date date) {
        SimpleDateFormat format = getDateFormat(sdf06);
        String time1 = format.format(date) + "000000";
        return Long.parseLong(time1);
    }

    public static Long getLongTime(Long time, Integer day, Integer hour) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(format11(String.valueOf(time)));
        ca.add(Calendar.DATE, -day);
        return Long.parseLong(getDateFormat(sdf06).format(ca.getTime()) + (hour > 9 ? hour : "0" + hour) + "0000");
    }

    public static Integer getHour(Long time) {
        return Integer.parseInt(String.valueOf(time).substring(8, 10));
    }

    /**
     * 上个月第一天
     *
     * @param date
     * @return
     */
    public static Long beginOfLastMonth(Date date) {
        SimpleDateFormat df = getDateFormat(sdf06);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -1);
        // Date theDate = calendar.getTime();

        // 上个月第一天
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String day_first = df.format(calendar.getTime());
        day_first = day_first + "000000";
        return Long.parseLong(day_first);
    }

    /**
     * 上个月最后一天
     *
     * @param date
     * @return
     */
    public static Long endOfLastMonth(Date date) {
        SimpleDateFormat df = getDateFormat(sdf06);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // calendar.add(Calendar.MONTH, -1);
        // calendar.add(Calendar.MONTH, 1); // 加一个月
        calendar.set(Calendar.DATE, 1); // 设置为当前月第一天
        calendar.add(Calendar.DATE, -1); // 再减一天即为上个月最后一天
        String day_last = df.format(calendar.getTime());
        day_last = day_last + "235959";
        return Long.parseLong(day_last);
    }

    /**
     * 上个月第一天
     *
     * @return
     */
    public static Long beginOfLastMonth() {
        SimpleDateFormat df = getDateFormat(sdf06);
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        // Date theDate = calendar.getTime();

        // 上个月第一天
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String day_first = df.format(calendar.getTime());
        day_first = day_first + "000000";
        return Long.parseLong(day_first);
    }

    /**
     * 上个月最后一天
     *
     * @return
     */
    public static Long endOfLastMonth() {
        SimpleDateFormat df = getDateFormat(sdf06);
        Calendar calendar = Calendar.getInstance();
        // calendar.add(Calendar.MONTH, -1);
        // calendar.add(Calendar.MONTH, 1); // 加一个月
        calendar.set(Calendar.DATE, 1); // 设置为当前月第一天
        calendar.add(Calendar.DATE, -1); // 再减一天即为上个月最后一天
        String day_last = df.format(calendar.getTime());
        day_last = day_last + "235959";
        return Long.parseLong(day_last);
    }

    /**
     * 任意月第一天
     *
     * @param date
     * @return
     */
    public static String beginOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // calendar.add(Calendar.MONTH, 0);
        // Date theDate = calendar.getTime();

        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String day_first = format06(calendar.getTime());
        day_first = day_first + "000000";
        return day_first;
    }

    /**
     * 任意月最后一天
     *
     * @param date
     * @return
     */
    public static String endOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // calendar.add(Calendar.MONTH, 0);
        calendar.add(Calendar.MONTH, 1); // 当前月加一个月
        calendar.set(Calendar.DATE, 1); // 设置为该月第一天
        calendar.add(Calendar.DATE, -1); // 再减一天即为当前月最后一天
        String day_last = format06(calendar.getTime());
        day_last = day_last + "235959";
        return day_last;
    }

    /**
     * 任意月第一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Date beginOfMonth(final String year, final String month) {
        String date07 = year;
        date07 += month.length() == 1 ? ("0" + month) : month;
        Date date = format05(date07);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);

        return format11(beginOfDay(calendar.getTime()));
    }

    /**
     * 任意月最后一天
     *
     * @param year
     * @param month
     * @return
     */
    public static Date endOfMonth(final String year, final String month) {
        String date07 = year;
        date07 += month.length() == 1 ? ("0" + month) : month;
        Date date = format05(date07);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 1); // 当前月加一个月
        calendar.set(Calendar.DATE, 1); // 设置为该月第一天
        calendar.add(Calendar.DATE, -1); // 再减一天即为当前月最后一天

        return format11(endOfDay(calendar.getTime()));
    }

    /**
     * 获取任意时间的上个月
     *
     * @param repeatDate
     * @return
     */
    public static String getLastMonth(String repeatDate) {
        String lastMonth = "";
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat dft = getDateFormat(sdf10);
        int year = Integer.parseInt(repeatDate.substring(0, 4));
        String monthsString = repeatDate.substring(4, 6);
        int month;
        if ("0".equals(monthsString.substring(0, 1))) {
            month = Integer.parseInt(monthsString.substring(1, 2));
        } else {
            month = Integer.parseInt(monthsString.substring(0, 2));
        }
        cal.set(year, month - 2, Calendar.DATE);
        lastMonth = dft.format(cal.getTime());
        return lastMonth;
    }

    /**
     * 获取任意时间的下一个月
     *
     * @param repeatDate
     * @return
     */
    public static String getNextMonth(String repeatDate, String Format) {
        String lastMonth = "";
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat dft = getDateFormat(Format);
        int year = Integer.parseInt(repeatDate.substring(0, 4));
        String monthsString = repeatDate.substring(4, 6);
        int month;
        if ("0".equals(monthsString.substring(0, 1))) {
            month = Integer.parseInt(monthsString.substring(1, 2));
        } else {
            month = Integer.parseInt(monthsString.substring(0, 2));
        }
        cal.set(year, month, Calendar.DATE);
        lastMonth = dft.format(cal.getTime());
        return lastMonth;
    }

    /**
     * 获取任意时间的下一个月
     *
     * @param repeatDate
     * @return
     */
    public static String getNextMonth(String repeatDate) {
        String lastMonth = "";
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat dft = getDateFormat(sdf10);
        int year = Integer.parseInt(repeatDate.substring(0, 4));
        String monthsString = repeatDate.substring(4, 6);
        int month;
        if ("0".equals(monthsString.substring(0, 1))) {
            month = Integer.parseInt(monthsString.substring(1, 2));
        } else {
            month = Integer.parseInt(monthsString.substring(0, 2));
        }
        cal.set(year, month, Calendar.DATE);
        lastMonth = dft.format(cal.getTime());
        return lastMonth;
    }

    /**
     * 获取指定日期的前后某天的开始时间<br>
     * Integer i<0 往过去推, i>0 往未来推
     *
     * @param i
     * @return
     */
    public static Long getDayAfterDate(Long date, int i) {
        if (date == null) {
            return null;
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(format11(date.toString()));
        ca.add(Calendar.DATE, i);
        return Long.parseLong(getDateFormat(sdf11).format(ca.getTime()));
    }

    /**
     * 获取指定日期的前后某月的开始时间<br>
     * Integer i<0 往过去推, i>0 往未来推
     *
     * @param i
     * @return
     */
    public static Long getDayAfterMonth(Long date, int i) {
        if (date == null) {
            return null;
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(format11(date.toString()));
        ca.add(Calendar.MONTH, i);
        return Long.parseLong(getDateFormat(sdf11).format(ca.getTime()));
    }

    public static List<Date> getAllDayOfMonth(Date date) {
        List<Date> list = new ArrayList<Date>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DATE, 1);
        int month = cal.get(Calendar.MONTH);
        while (cal.get(Calendar.MONTH) == month) {
            list.add(cal.getTime());
            cal.add(Calendar.DATE, 1);
        }
        return list;
    }

    /**
     * 根据开始时间和结束时间返回时间段内的时间集合
     *
     * @param beginDate
     * @param endDate
     * @return List
     */
    public static List<Date> getDatesBetweenTwoDate(Date beginDate, Date endDate) {
        List<Date> lDate = new ArrayList<Date>();
        lDate.add(beginDate);// 把开始时间加入集合
        Calendar cal = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        cal.setTime(beginDate);
        boolean bContinue = true;
        while (bContinue) {
            // 根据日历的规则，为给定的日历字段添加指定的时间量
            cal.add(Calendar.DAY_OF_MONTH, 1);
            // 测试此日期是否在指定日期之后
            if (endDate.after(cal.getTime())) {
                lDate.add(cal.getTime());
            } else {
                break;
            }
        }
        lDate.add(endDate);// 把结束时间加入集合
        return lDate;
    }

    /**
     * 是否是今天
     *
     * @param time
     * @return
     */
    public static boolean isToday(Long time) {
        return time != null && format09(new Date()).equals(Long11ToStr09(time));
    }

    /**
     * 给定时间减去固定的小时
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long reduceHoursLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return addHoursLong(time, -amount);
    }

    /**
     * 给定时间减去固定的分钟
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long reduceMinutesLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return addMinutesLong(time, -amount);
    }

    /**
     * 将当前时间增加指定的秒数-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addSecondsLong(int amount) {
        return format11Long(addSeconds(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的分钟-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addMinutesLong(int amount) {
        return format11Long(addMinutes(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的小时-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addHoursLong(int amount) {
        return format11Long(addHours(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的天数-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addDaysLong(int amount) {
        return format11Long(addDays(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的周数-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addWeeksLong(int amount) {
        return format11Long(addWeeks(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的月数-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addMonthsLong(int amount) {
        return format11Long(addMonths(getNowDate(), amount));
    }

    /**
     * 将当前时间增加指定的月数-返回14位数字的时间
     *
     * @param amount
     * @return
     */
    public static Long addYearsLong(int amount) {
        return format11Long(addYears(getNowDate(), amount));
    }

    /**
     * 给定时间增加固定的秒数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addSecondsLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addSeconds(format11(time), amount));
    }

    /**
     * 给定时间增加固定的分钟
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addMinutesLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addMinutes(format11(time), amount));
    }

    /**
     * 给定时间增加固定的小时
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addHoursLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addHours(format11(time), amount));
    }

    /**
     * 给定时间增加固定的天数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addDaysLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addDays(format11(time), amount));
    }

    /**
     * 给定时间增加固定的天数
     *
     * @param time   yyyyMMdd
     * @param amount
     * @return
     */
    public static Integer addDays(Integer time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format06Int(addDays(format06(time), amount));
    }

    /**
     * 给定时间增加固定的周数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addWeeksLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addWeeks(format11(time), amount));
    }

    /**
     * 给定时间增加固定的月数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addMonthsLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addMonths(format11(time), amount));
    }

    /**
     * 给定时间增加固定的年数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Long addYearsLong(Long time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        return format11Long(addYears(format11(time), amount));
    }

    /**
     * 给定月份(yyyyMM)增加固定的月数
     *
     * @param time
     * @param amount
     * @return
     */
    public static Integer addTime05Month(Integer time, int amount) {
        if (time == null || time <= 0) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(format05(time.toString()));
        cal.add(Calendar.MONTH, amount);
        return Integer.parseInt(getDateFormat(sdf05).format(cal.getTime()));
    }

    /**
     * 获取当日的前后某天的开始时间 23：59：59 Integer i<0 往前推 i>0 往后推(yyyy-MM-dd)
     */
    public static String getDayLeftOrRightTime(int i) {
        Calendar ca = Calendar.getInstance();
        // ca.setTime(new Date());
        ca.add(Calendar.DATE, i);
        return getDateFormat(sdf09).format(ca.getTime());
    }

    /**
     * 将14位的日期转为生日 MMdd
     *
     * @param time
     * @return
     */
    public static Long Long11ToMMdd(Long time) {
        if (time == null) {
            return null;
        }
        if (String.valueOf(time).length() != 14) {
            return null;
        }
        return Long.parseLong(String.valueOf(time).substring(4, 8));
    }

    /**
     * 将包含特殊字符的日期字符串转为14位
     *
     * @param date
     * @return
     * @throws Exception
     */
    public static String dateFormatString(String date) throws Exception {
        if (StrUtil.isEmpty(date) || "null".equalsIgnoreCase(date)) {
            return null;
        }
        if (date.contains("/")) {
            return getDateFormat(sdf11).format(getDateFormat(sdf25).parse(date));
        } else if (date.contains(".")) {
            return getDateFormat(sdf11).format(getDateFormat(sdf26).parse(date));
        } else if (date.contains("-")) {
            return getDateFormat(sdf11).format(format07(date));
        } else {
            return date;
        }
    }

    /**
     * 13位unix时间戳转sdf11
     *
     * @param time
     * @return
     */
    public static Long getTimeFromStamp(long time) {
        return Long.parseLong(getDateFormat(sdf11).format(new Date(time)));
    }

    /**
     * sdf11转13位unix时间戳
     *
     * @param time
     * @return
     */
    public static Long getStampFromTime(Long time) {
        try {
            return format11(time.toString()).getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0L;
    }

    /**
     * 微信里面的时间戳转换成14位时间
     *
     * @param time
     * @return
     */
    public static Long wxCreateTimeToLong11(String time) {
        return Long.parseLong(getDateFormat(sdf11).format(new Date(Long.parseLong(time) * 1000L)));
    }

    /**
     * 根据给定的时间-转换成微信使用的时间戳格式
     *
     * @param time
     * @return
     */
    public static int long09TimeToWx(String time) {
        return (int) ((format09(time).getTime()) / 1000);
    }

    /**
     * 将秒数转为*天*小时*分*秒返回
     *
     * @param second
     * @return
     */
    public static String secondsBetweenLong(int second) {
        StringBuilder DateTimes = new StringBuilder();
        long days = second / (60 * 60 * 24);
        long hours = (second % (60 * 60 * 24)) / (60 * 60);
        long minutes = (second % (60 * 60)) / 60;
        long seconds = second % 60;
        if (days > 0) {
            DateTimes.append(days).append("天").append(hours).append("小时").append(minutes).append("分钟").append(seconds).append("秒");
        } else if (hours > 0) {
            DateTimes.append(hours).append("小时").append(minutes).append("分钟").append(seconds).append("秒");
        } else if (minutes > 0) {
            DateTimes.append(minutes).append("分钟").append(seconds).append("秒");
        } else {
            DateTimes.append(seconds).append("秒");
        }
        return DateTimes.toString();
    }

    /**
     * 获取当前日期跟当前日期后一个月的日期
     *
     * @return
     */
    public static String[] afterMonth() {
        String[] strings = new String[2];
        Date dt = new Date();
        strings[0] = getDateFormat(sdf09).format(dt);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dt);
        calendar.add(Calendar.MONTH, 1);
        String dateStr = getDateFormat(sdf09).format(calendar.getTime());
        strings[1] = dateStr;
        return strings;
    }

    /**
     * 获取当前时间10位时间戳
     *
     * @return
     */
    public static long getNowTimeStamp() {
        return System.currentTimeMillis() / 1000;
    }

    /**
     * 获取当前时间10位时间戳(int)
     *
     * @return
     */
    public static int getNowTimeStampInt() {
        return (int) getNowTimeStamp();
    }

    /**
     * 获取当前时间10位时间戳
     *
     * @return
     */
    public static String getNowTimeStampStr() {
        return String.valueOf(System.currentTimeMillis() / 1000);
    }

    /**
     * long日期转换成10位时间戳
     *
     * @param dateStr 字符串日期
     * @return
     */
    public static long Long11ToTimeStamp(long dateStr) {
        return format11(String.valueOf(dateStr)).getTime() / 1000;
    }

    /**
     * long日期转换成10位时间戳
     *
     * @param dateStr 字符串日期
     * @return
     */
    public static String Long11ToTimeStampStr(long dateStr) {
        return String.valueOf(format11(String.valueOf(dateStr)).getTime() / 1000);
    }

    /**
     * 日期格式字符串转换成10位时间戳
     *
     * @param dateStr 字符串日期
     * @param format  如：yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static long DateToTimeStamp(String dateStr, String format) {
        return getDateFormat(dateStr, format).getTime() / 1000;
    }

    /**
     * 获取当前时间往后推i天
     */
    public static Long getDateAfterDay(String date, Integer i) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(format09(date));
        ca.add(Calendar.DATE, i);
        return Long.parseLong(getDateFormat("yyyyMMdd").format(ca.getTime()));
    }

    /**
     * 获取当前时间往后推i天
     */
    public static Long getDateAfterDay(Integer i) {
        Calendar ca = Calendar.getInstance();
        // ca.setTime(new Date());
        ca.add(Calendar.DATE, i);
        return Long.parseLong(getDateFormat("yyyyMMdd").format(ca.getTime()));
    }

    /**
     * 获取指定时间的当天的开始时间
     *
     * @param time
     * @return
     */
    public static Long getTime11Start(Long time) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(format11(String.valueOf(time)));
        return Long.parseLong(getDateFormat(sdf06).format(ca.getTime()) + "000000");
    }

    /**
     * 获取指定时间的当天的结束时间
     *
     * @param time
     * @return
     */
    public static Long getTime11End(Long time) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(format11(String.valueOf(time)));
        return Long.parseLong(getDateFormat(sdf06).format(ca.getTime()) + "235959");
    }

    /**
     * 判断两个时间段是否有重叠
     *
     * @param s1
     * @param e1
     * @param s2
     * @param e2
     * @return
     */
    public static boolean theTimeIsOverOther(long s1, long e1, long s2, long e2) {
        if (s1 >= e1 || s2 >= e2) {
            return false;
        }
        if (s2 >= s1 && s2 < e1) {
            return true;
        }
        if (e2 > s1 && e2 <= e1) {
            return true;
        }
        return s2 <= s1 && e2 >= e1;
    }

    /**
     * 获取毫秒时间戳
     *
     * @param date   时间 如 20181227194600
     * @param format 对应date的格式 如 yyyyMMddHHmmss
     * @return 毫秒时间戳
     */
    public static Long getTimeMillis(Long date, String format) {
        if (date != null) {
            return getDateFormat(date.toString(), format).getTime();
        }
        return null;
    }

    /**
     * 将yyyy-MM-dd转成yyyyMMdd格式
     *
     * @param time
     * @return
     */
    public static String str09to06(String time) {
        if (time == null || "".equals(time) || !time.contains("-")) {
            return time;
        }
        return getDateFormat(sdf06).format(format09(time));
    }

    public static String str07to19(String time) {
        if (time == null || "".equals(time) || !time.contains("-")) {
            return time;
        }
        return getDateFormat(sdf19).format(format07(time));
    }

    /**
     * 将yyyyMMdd转成yyyy-MM-dd格式
     *
     * @param time
     * @return
     */
    public static String str06t09(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf09).format(format06(time));
    }

    /**
     * 将yyyyMMddHHmmss转成yyyy-MM-dd格式
     *
     * @param time
     * @return
     */
    public static String str11t09(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf09).format(format11(time));
    }

    /**
     * 将yyyyMMddHHmmss转成yyyy-MM-dd格式
     *
     * @param time
     * @return
     */
    public static String str07t11(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf11).format(format07(time));
    }

    /**
     * 将yyyyMMddHHmmss转成HH:mm格式
     *
     * @param time
     * @return
     */
    public static String str11t21(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf21).format(format11(time));
    }

    /**
     * 将yyyyMMddHHmmss转成yyyy-MM-dd HH:mm格式
     *
     * @param time
     * @return
     */
    public static String str11t19(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf19).format(format11(time));
    }

    /**
     * 将yyyyMMddHHmmss转成yyyy-MM-dd HH:mm:ss格式
     *
     * @param time
     * @return
     */
    public static String str11t07(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf07).format(format11(time));
    }

    /**
     * 将yyyyMM转成yyyy-MM格式
     *
     * @param time
     * @return
     */
    public static String str05t10(String time) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(sdf10).format(format05(time));
    }

    /**
     * 将yyyyMM转成yyyy-MM格式
     *
     * @param time
     * @return
     */
    public static String FormatChange(String time, String format, String to) {
        if (time == null || "".equals(time)) {
            return time;
        }
        return getDateFormat(to).format(getDateFormat(time, format));
    }

    /**
     * poi读出来的日期
     *
     * @param day
     * @return
     */
    public static String poiGetDate(int day) {
        Calendar cal = new GregorianCalendar(1900, 0, -1);
        cal.add(Calendar.DATE, day);
        Date d = cal.getTime();
        return getDateFormat(sdf06).format(d);
    }

    /**
     * 根据指定的开始日期和结束日期得出中间日期
     *
     * @param start
     * @param end
     * @return
     */
    public static List<Date> findDates(Date start, Date end) {
        if (start == null || end == null) {
            return null;
        }
        List<Date> list = new ArrayList<Date>();
        list.add(start);
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(start);// 使用给定的 Date 设置此 Calendar 的时间
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(end);// 使用给定的 Date 设置此 Calendar 的时间
        // 测试此日期是否在指定日期之后
        while (end.after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH, 1);// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            list.add(calBegin.getTime());
        }
        return list;
    }

    /**
     * 根据指定的开始日期和结束日期得出中间日期(天)-yyyyMMdd
     *
     * @param start 06-yyyyMMdd
     * @param end   06-yyyyMMdd
     * @return
     */
    public static List<String> getBetweenDayByStartEndDay(String start, String end) {
        if (StrUtil.isEmpty(start) || StrUtil.isEmpty(end)) {
            return null;
        }
        List<String> list = new ArrayList<>();
        list.add(start);
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(format06(start));// 使用给定的 Date 设置此 Calendar 的时间
        Calendar calEnd = Calendar.getInstance();
        Date endDate = format06(end);
        calEnd.setTime(endDate);// 使用给定的 Date 设置此 Calendar 的时间
        // 判断此日期是否在指定日期之后
        while (endDate.after(calBegin.getTime())) {
            calBegin.add(Calendar.DAY_OF_MONTH, 1);// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            list.add(format06(calBegin.getTime()));
        }
        return list;
    }

    /**
     * 根据指定的开始日期和结束日期得出中间日期(月)-yyyyMM
     *
     * @param start
     * @param end
     * @return
     */
    public static List<String> getBetweenMonthByStartEndDay(String start, String end) {
        if (StrUtil.isEmpty(start) || StrUtil.isEmpty(end)) {
            return null;
        }
        List<String> list = new ArrayList<>();
        list.add(start);
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(format05(start));// 使用给定的 Date 设置此 Calendar 的时间
        Calendar calEnd = Calendar.getInstance();
        Date endDate = format05(end);
        calEnd.setTime(endDate);// 使用给定的 Date 设置此 Calendar 的时间
        // 判断此日期是否在指定日期之后
        while (endDate.after(calBegin.getTime())) {
            calBegin.add(Calendar.MONTH, 1);// 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            list.add(format05(calBegin.getTime()));
        }
        return list;
    }

    /**
     * 根据月份获取当前月最后一天
     *
     * @param month
     * @return
     */
    public static String getLastDayByMonth(String month) {
        String monthDay = DateUtil.getNextMonth(month, DateUtil.sdf05);
        monthDay = FormatChange(monthDay, DateUtil.sdf05, DateUtil.sdf06);
        Calendar cal = Calendar.getInstance();
        cal.setTime(format06(monthDay));
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return format06(cal.getTime());
    }

    public static int between_days(String a, String b) {
        a = StrUtil.rightPad(a, 14, "0");
        b = StrUtil.rightPad(b, 14, "0");
        SimpleDateFormat simpleDateFormat = getDateFormat(DateUtil.sdf11);// 自定义时间格式
        Calendar calendar_a = Calendar.getInstance();// 获取日历对象
        Calendar calendar_b = Calendar.getInstance();
        Date date_a;
        Date date_b;
        try {
            date_a = simpleDateFormat.parse(a);// 字符串转Date
            date_b = simpleDateFormat.parse(b);
            calendar_a.setTime(date_a);// 设置日历
            calendar_b.setTime(date_b);
        } catch (ParseException e) {
            e.printStackTrace();// 格式化异常
        }
        long time_a = calendar_a.getTimeInMillis();
        long time_b = calendar_b.getTimeInMillis();
        return (int) ((time_b - time_a) / (1000 * 3600 * 24));
    }

    public static String Long11toSdf19(Long time) {
        if (time == null) {
            return "";
        }
        return getDateFormat(sdf19).format(format11(time.toString()));
    }

    /**
     * 14位unix时间戳转202002021001090000
     *
     * @param time
     * @return
     */
    public static Long getTimeFromLong(long time) {
        return Long.parseLong(getDateFormat(sdf11).format(new Date(time)));
    }

    /**
     * 202002021001090000转14位unix时间戳
     *
     * @param time
     * @return
     */
    public static Long getLongFromTime(Long time) {
        try {
            return format11(time.toString()).getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0L;
    }

    /**
     * 获取指定日期的天数
     */
    public static int getCurrentMonthDay(Long times, int is) {
        int day = 0;
        for (int i = 1; i < is; i++) {
            day += getCurrentMonthDay(addMonthsLong(times, i), 0);
        }
        int year = Integer.parseInt(times.toString().substring(0, 4));
        int month = Integer.parseInt(times.toString().substring(4, 6));
        Calendar a = Calendar.getInstance();
        a.set(Calendar.YEAR, year);
        a.set(Calendar.MONTH, month - 1);
        a.set(Calendar.DATE, 1);
        a.roll(Calendar.DATE, -1);
        int maxDate = a.get(Calendar.DATE);
        return maxDate + day;
    }

    /**
     * 计算距离当天剩余多少秒
     *
     * @param currentDate
     * @return
     */
    public static Integer getRemainSecondsOneDay(Date currentDate) {
        Calendar midnight = Calendar.getInstance();
        midnight.setTime(currentDate);
        midnight.add(Calendar.DAY_OF_MONTH, 1);
        midnight.set(Calendar.HOUR_OF_DAY, 0);
        midnight.set(Calendar.MINUTE, 0);
        midnight.set(Calendar.SECOND, 0);
        midnight.set(Calendar.MILLISECOND, 0);
        return (Integer) (int) ((midnight.getTime().getTime() - currentDate.getTime()) / 1000);
    }

    /**
     * 指定格式日期加减后的新日期
     *
     * @param num
     * @param date
     * @return
     */
    public static Integer getDateByNum(Integer num, Integer date) {
        try {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = getDateFormat(sdf06);
            cal.setTime(sdf.parse(String.valueOf(date)));
            cal.add(Calendar.DATE, num);
            return Integer.valueOf(sdf.format(cal.getTime()));
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 获取格式化时间，格式为2021-06-14(周一) 09:00
     */
    public static String getSdf19WithWeekInMiddle(Long time) {
        try {
            if (null == time) {
                return null;
            }
            String timeStr = String.valueOf(time);
            String week = dayForWeek(timeStr);
            String sdf19Str = Long11ToStr19(time);
            String[] sdf19StrArr = sdf19Str.split(" ");
            return sdf19StrArr[0] + "(" + week + ")" + " " + sdf19StrArr[1];
        } catch (Exception ignored) {
        }
        return null;
    }

    /**
     * 获取格式化时间，格式为2021-06-14 09:00(周一)
     */
    public static String getSdf19WithWeekAtEnd(Long time) {
        try {
            if (null == time) {
                return null;
            }
            String timeStr = String.valueOf(time);
            String week = dayForWeek(timeStr);
            String sdf19Str = Long11ToStr19(time);
            return sdf19Str + " " + "(" + week + ")";
        } catch (Exception ignored) {
        }
        return null;
    }

    /**
     * 获取当前到今天结束的秒数
     *
     * @return
     */
    public static Integer getSecondsFromNowToTodayEnd() {
        SimpleDateFormat simpleDateFormat06 = getDateFormat(sdf06);
        SimpleDateFormat simpleDateFormat11 = getDateFormat(sdf11);
        Date now = new Date();
        Long timeStart = Long.valueOf(simpleDateFormat11.format(now));
        Long timeEnd = addDaysLong(Long.valueOf(simpleDateFormat06.format(now) + "000000"), 1);
        return betweenSecond(timeStart, timeEnd);
    }

    /**
     * 获取开始结束日期
     *
     * @param time yyyy-MM-dd - yyyy-MM-dd
     * @return
     */
    public static List<Date> getStartEndDate(final String time) {
        List<Date> date = new ArrayList<>(2);
        String start = null, end = null;
        if (StrUtil.notBlank(time)) {
            String s = DateUtil.dateReplace2Int(time);
            if (s.length() == 16) {
                start = s.substring(0, 8);
                end = s.substring(8, 16);
            }
        }
        if (StrUtil.notBlank(start) && StrUtil.notBlank(end)) {
            date.add(DateUtil.format11(start + "000000"));
            date.add(DateUtil.format11(end + "235959"));
        }
        return date;
    }

    /**
     * 获取开始结束日期时间
     *
     * @param time yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static List<Date> getStartEndDateTime(final String time) {
        List<Date> date = new ArrayList<>(2);
        String start = null, end = null;
        if (StrUtil.notBlank(time)) {
            String s = DateUtil.dateReplace2Int(time);
            if (s.length() == 28) {
                start = s.substring(0, 14);
                end = s.substring(14, 28);
            }
        }
        if (StrUtil.notBlank(start) && StrUtil.notBlank(end)) {
            date.add(DateUtil.format11(start));
            date.add(DateUtil.format11(end));
        }
        return date;
    }

    /**
     * 拼接课程上课时间-带周几
     *
     * @param startTime
     * @param endTime
     * @return yyyy-MM-dd (周几) HH:mm-HH:mm
     */
    public static String joinClassDate09Week(Long startTime, Long endTime) {
        if (startTime == null) {
            return null;
        }
        return Long11ToStr09(startTime) + " [" + getWeek(startTime.toString()) + "] " + Long11ToStr21(startTime) + "-" + Long11ToStr21(endTime);
    }

    /**
     * 拼接课程上课时间-带周几
     *
     * @param time
     * @return yyyy-MM-dd (周几) HH:mm
     */
    public static String joinClassDate09Week(Long time) {
        if (time == null) {
            return null;
        }
        return DateUtil.Long11ToStr09(time) + " [" + DateUtil.dayForWeek(time) + "] " + Long11ToStr21(time);
    }

    /**
     * 拼接课程上课时间-带周几
     *
     * @param startTime
     * @param endTime
     * @return yy-MM-dd (周几) HH:mm-HH:mm
     */
    public static String joinClassDate34Week(Long startTime, Long endTime) {
        if (startTime == null) {
            return null;
        }
        return Long11ToStr34(startTime) + " [" + getWeek(startTime.toString()) + "] " + Long11ToStr21(startTime) + "-" + Long11ToStr21(endTime);
    }

    /**
     * 拼接课程上课时间
     *
     * @param startTime
     * @param endTime
     * @return yy-MM-dd HH:mm-HH:mm
     */
    public static String joinClassDate34(Long startTime, Long endTime) {
        if (startTime == null) {
            return null;
        }
        return Long11ToStr34(startTime) + " " + Long11ToStr21(startTime) + "-" + Long11ToStr21(endTime);
    }

    /**
     * 计算两日期段交集
     *
     * @param sd1 第一日期段~开始
     * @param ed1 第一日期段~结束
     * @param sd2 第二日期段~开始
     * @param ed2 第二日期段~结束
     * @return 交集的日期 yyyy-MM-dd#yyyy-MM-dd
     */
    public static String countDate09Intersection(Date sd1, Date ed1, Date sd2, Date ed2) {
        SimpleDateFormat sdf2 = getDateFormat(sdf09);
        long s1 = 0;
        long s2 = 0;
        long e1 = 0;
        long e2 = 0;
        try {
            s1 = sdf2.parse(sdf2.format(sd1)).getTime();
            s2 = sdf2.parse(sdf2.format(sd2)).getTime();
            e1 = sdf2.parse(sdf2.format(ed1)).getTime();
            e2 = sdf2.parse(sdf2.format(ed2)).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (!(s2 > e1 || s1 > e2)) {
            long s = Math.max(s1, s2);
            long e = Math.min(e1, e2);
            return format09(new Date(s)) + StaticVar.CROSS_HATCH + format09(new Date(e));
        }
        return null;
    }

    /**
     * 获取date年后的amount年的第month月弟day天的时间
     *
     * @param amount 可正、可负
     * @return
     */
    public static Date getSpecficYearDate(Date date, int amount, int month, int day) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.YEAR, amount);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, day);
        return format11(endOfDay(cal.getTime()));
    }

    public static void main(String[] args) {
        System.out.println(beginOfMonth("2023", "2"));
    }
}
